let Hero = class extends Laya.Sprite{

    constructor(){
        super()

        this.className = "Hero"

        this.img = new Laya.Sprite()
        this.speed = 10
      
        this.init()
    }

    init(){
          this.img.loadImage("red.png")
          this.addChild(this.img)
          this.pos(0,320)


        Laya.stage.on(Laya.Event.CLICK,this,this.run)
    }

    run(){
        if(this.x == 0){
            Laya.timer.frameLoop(1,this,this.right)
        }else if(this.x == 160){
            Laya.timer.frameLoop(1,this,this.left)
        }
    }

    right(){
       
            this.x += this.speed
            if(this.x >= 160){
                Laya.timer.clear(this,this.right)
                this.x = 160
            }
       
    }

    left(){
           
            this.x -= this.speed
             if(this.x <= 0){
                Laya.timer.clear(this,this.left)
                this.x = 0
            }
        
    }


}